<?php

namespace Home\DAO;

use Home\Common\FIdConst;

/**
 * 习题库 DAO
 *
 * @author 李静波
 */
class DrillCategoryDAO extends PSIBaseExDAO {

	/**
	 * 返回习题分类列表
	 *
	 * @param array $params        	
	 * @return array
	 */
	public function drillCategoryList($params) {
		$loginUserId = $params["loginUserId"];
		
		$db = $this->db;
		
		$sql = "select c.id, c.code, c.name
				from t_drill_category c ";
		$queryParams = [];
		$ds = new DataOrgDAO($db);
		$rs = $ds->buildSQL(FIdConst::DRILL_REPO, "c", $loginUserId);
		if ($rs) {
			$sql .= " where " . $rs[0];
			$queryParams = $rs[1];
		}
		
		$sql .= " order by c.code ";
		
		$data = $db->query($sql, $queryParams);
		$result = [];
		
		foreach ( $data as $v ) {
			$result[] = [
					"id" => $v["id"],
					"name" => $v["name"],
					"code" => $v["code"]
			];
		}
		
		return $result;
	}
}